import { EntityObjectFactory } from './../entityObjectFactory';
var EntityObject = EntityObjectFactory.GetEntityObjectType();
import { Identity } from '../../common/authentication/identity';
import { MD5, Guid } from "../../common/utils";

export class Token extends EntityObject<Token> {
    id: string;
    TokenValue: string;
    CreateTime: Date | string;
    Identity: Identity;
    constructor(user: Identity, tokenValue?, ctx?) {
        super(ctx);
        this.id = Guid.GetGuid();
        this.CreateTime = new Date(Date.now());
        this.Identity = user;
        if (tokenValue) {
            this.TokenValue = tokenValue;
        }
        else {
            if (user) {
                //通过用户名和id,密码，生成哈希code
                let s = user.userId + user.userName + user.password;
                this.TokenValue = MD5.calcMD5(s);
            }
        }
    }

    toString() {
        return "Token";
    }
}